package com.school.common;

/**
 * 响应码枚举
 * 
 * @author School Development Team
 * @version 1.0.0
 * @since 2024
 */
public enum ResultCode {

    // 通用响应码
    SUCCESS(200, "操作成功"),
    ERROR(500, "操作失败"),
    
    // 参数相关 1xxx
    PARAM_ERROR(1001, "参数错误"),
    PARAM_MISSING(1002, "参数缺失"),
    PARAM_INVALID(1003, "参数无效"),
    PARAM_TYPE_ERROR(1004, "参数类型错误"),
    
    // 认证授权相关 2xxx
    UNAUTHORIZED(2001, "未授权访问"),
    TOKEN_INVALID(2002, "Token无效"),
    TOKEN_EXPIRED(2003, "Token已过期"),
    LOGIN_FAILED(2004, "登录失败"),
    PERMISSION_DENIED(2005, "权限不足"),
    ACCOUNT_LOCKED(2006, "账户已锁定"),
    ACCOUNT_DISABLED(2007, "账户已禁用"),
    PASSWORD_ERROR(2008, "密码错误"),
    
    // 业务相关 3xxx
    DATA_NOT_FOUND(3001, "数据不存在"),
    DATA_ALREADY_EXISTS(3002, "数据已存在"),
    DATA_IN_USE(3003, "数据正在使用中"),
    OPERATION_NOT_ALLOWED(3004, "操作不被允许"),
    STATUS_ERROR(3005, "状态错误"),
    
    // 学生管理相关 31xx
    STUDENT_NOT_FOUND(3101, "学生不存在"),
    STUDENT_ALREADY_EXISTS(3102, "学生已存在"),
    STUDENT_ID_CARD_EXISTS(3103, "身份证号已存在"),
    STUDENT_CLASS_FULL(3104, "班级人数已满"),
    STUDENT_STATUS_ERROR(3105, "学生状态错误"),
    
    // 教师管理相关 32xx
    TEACHER_NOT_FOUND(3201, "教师不存在"),
    TEACHER_ALREADY_EXISTS(3202, "教师已存在"),
    TEACHER_EMAIL_EXISTS(3203, "教师邮箱已存在"),
    TEACHER_HAS_STUDENTS(3204, "教师名下还有学生"),
    
    // 班级管理相关 33xx
    CLASS_NOT_FOUND(3301, "班级不存在"),
    CLASS_ALREADY_EXISTS(3302, "班级已存在"),
    CLASS_HAS_STUDENTS(3303, "班级内还有学生"),
    CLASS_CAPACITY_EXCEEDED(3304, "班级容量超限"),
    
    // 课程管理相关 34xx
    COURSE_NOT_FOUND(3401, "课程不存在"),
    COURSE_ALREADY_EXISTS(3402, "课程已存在"),
    COURSE_CODE_EXISTS(3403, "课程代码已存在"),
    COURSE_HAS_GRADES(3404, "课程已有成绩记录"),
    
    // 成绩管理相关 35xx
    GRADE_NOT_FOUND(3501, "成绩记录不存在"),
    GRADE_ALREADY_EXISTS(3502, "成绩记录已存在"),
    GRADE_SCORE_INVALID(3503, "成绩分数无效"),
    GRADE_EXAM_DATE_INVALID(3504, "考试日期无效"),
    
    // 考勤管理相关 36xx
    ATTENDANCE_NOT_FOUND(3601, "考勤记录不存在"),
    ATTENDANCE_ALREADY_EXISTS(3602, "考勤记录已存在"),
    ATTENDANCE_DATE_INVALID(3603, "考勤日期无效"),
    
    // 文件相关 4xxx
    FILE_UPLOAD_ERROR(4001, "文件上传失败"),
    FILE_TYPE_NOT_ALLOWED(4002, "文件类型不允许"),
    FILE_SIZE_EXCEEDED(4003, "文件大小超限"),
    FILE_NOT_FOUND(4004, "文件不存在"),
    
    // 系统相关 5xxx
    SYSTEM_ERROR(5001, "系统错误"),
    DATABASE_ERROR(5002, "数据库错误"),
    NETWORK_ERROR(5003, "网络错误"),
    CACHE_ERROR(5004, "缓存错误"),
    CONFIG_ERROR(5005, "配置错误"),
    
    // 限流相关 6xxx
    RATE_LIMIT_EXCEEDED(6001, "请求频率超限"),
    CONCURRENT_LIMIT_EXCEEDED(6002, "并发数超限"),
    
    // 第三方服务相关 7xxx
    THIRD_PARTY_ERROR(7001, "第三方服务错误"),
    SMS_SEND_ERROR(7002, "短信发送失败"),
    EMAIL_SEND_ERROR(7003, "邮件发送失败");

    private final Integer code;
    private final String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    /**
     * 根据code获取枚举
     */
    public static ResultCode getByCode(Integer code) {
        for (ResultCode resultCode : values()) {
            if (resultCode.getCode().equals(code)) {
                return resultCode;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return "ResultCode{" +
                "code=" + code +
                ", message='" + message + '\'' +
                '}';
    }
}